<html>
<head><meta charset="utf-8"><title>Revised RFC · project-ffi-unwind · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/index.html">project-ffi-unwind</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Revised.20RFC.html">Revised RFC</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="195349576"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Revised%20RFC/near/195349576" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Revised.20RFC.html#195349576">(Apr 26 2020 at 19:48)</a>:</h4>
<p>Okay, I've revised the RFC based on the comments and requested re-review from Niko.</p>
<p>I made one major change: I said we consider forced unwind across frames with destructors to be UB regardless of platform or ABI spec. The rationale is in the comments and the updated text.</p>



<a name="195428180"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Revised%20RFC/near/195428180" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Revised.20RFC.html#195428180">(Apr 27 2020 at 14:48)</a>:</h4>
<p><span class="user-mention" data-user-id="120076">@BatmanAoD (Kyle Strand)</span> nice! will review</p>



<a name="195737547"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Revised%20RFC/near/195737547" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Revised.20RFC.html#195737547">(Apr 29 2020 at 16:39)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> <span class="user-mention" data-user-id="116009">@nikomatsakis</span> Do either of you have any issues I can try to address before we sync tomorrow?</p>



<a name="195743371"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Revised%20RFC/near/195743371" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Revised.20RFC.html#195743371">(Apr 29 2020 at 17:27)</a>:</h4>
<p>let me review</p>



<a name="195746440"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Revised%20RFC/near/195746440" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Revised.20RFC.html#195746440">(Apr 29 2020 at 17:50)</a>:</h4>
<p>left some thoughts</p>



<a name="195782286"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Revised%20RFC/near/195782286" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Revised.20RFC.html#195782286">(Apr 29 2020 at 23:21)</a>:</h4>
<p>I'm generally not a fan of the term "forced unwinding" and all the complications around it.</p>



<a name="195782394"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Revised%20RFC/near/195782394" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Revised.20RFC.html#195782394">(Apr 29 2020 at 23:22)</a>:</h4>
<p>It is a concept that is originally from the Itanium ABI, and which we extended to include Windows' longjmp as well.</p>



<a name="195782468"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Revised%20RFC/near/195782468" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Revised.20RFC.html#195782468">(Apr 29 2020 at 23:23)</a>:</h4>
<p>I feel that it would be clearer if we instead talked in terms of the <em>source</em> of the unwind.</p>



<a name="195782654"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Revised%20RFC/near/195782654" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Revised.20RFC.html#195782654">(Apr 29 2020 at 23:25)</a>:</h4>
<p>So first we describe the behavior of unwinding caused by Rust panics <em>only</em>. And how that interacts with <code>extern "C"</code>, <code>extern "Rust"</code> and <code>extern "C unwind"</code> under <code>panic=abort</code> and <code>panic=unwind</code>. This includes describing how such a panic behaves when unwinding through foreign code ("just like a C++ exception").</p>



<a name="195782779"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Revised%20RFC/near/195782779" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Revised.20RFC.html#195782779">(Apr 29 2020 at 23:27)</a>:</h4>
<p>The base rule is that foreign unwinding (which we define as "returning to the parent frame without returning from a function normally") is UB by default unless specifically allowed in this RFC.</p>



<a name="195783188"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Revised%20RFC/near/195783188" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Revised.20RFC.html#195783188">(Apr 29 2020 at 23:32)</a>:</h4>
<p>Then we list the exceptions:</p>
<ul>
<li>C++ exceptions: UB if it uses a different unwind mechanism than use (e.g. dw2 vs sjlj vs seh). UB if it crosses a <code>catch_unwind</code> frame. Allowed if t enters &amp; exits Rust code via <code>extern "C unwind"</code>. </li>
<li>Normal <code>longjmp</code>: UB if any destructors or <code>catch_unwind</code> are skipped. Allowed otherwise.</li>
<li>Windows <code>longjmp</code>: Destructors allowed if it enters &amp; exits Rust code via <code>extern "C unwind"</code>. Otherwise same as normal <code>longjmp</code>.</li>
<li>Normal <code>pthread_exit</code>/<code>pthread_cancel</code>: UB if any destructors or <code>catch_unwind</code> are skipped. Allowed otherwise.</li>
<li>Glibc <code>pthread_exit</code>/<code>pthread_cancel</code>: Destructors allowed if it enters &amp; exits Rust code via <code>extern "C unwind"</code>. Otherwise same as normal <code>longjmp</code>.</li>
</ul>



<a name="195783235"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Revised%20RFC/near/195783235" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Revised.20RFC.html#195783235">(Apr 29 2020 at 23:33)</a>:</h4>
<p>Notice how there is no mention of "forced unwinding". Just rules for the different types of unwinding. And everything else is UB by default.</p>



<a name="195783278"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Revised%20RFC/near/195783278" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Revised.20RFC.html#195783278">(Apr 29 2020 at 23:33)</a>:</h4>
<p>(I was a bit more liberal in the rules than what we originally agreed with, but it's just to show an example).</p>



<a name="195786017"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Revised%20RFC/near/195786017" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Revised.20RFC.html#195786017">(Apr 30 2020 at 00:11)</a>:</h4>
<p>Hm. I may be biased by the sunk cost of having written a draft already, but I don't see why that approach would be better.</p>



<a name="195786200"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Revised%20RFC/near/195786200" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Revised.20RFC.html#195786200">(Apr 30 2020 at 00:14)</a>:</h4>
<p>Though admittedly the existing draft does not acknowledge different unwind mechanisms, and I'm not sure what it needs to say about them.</p>



<a name="195786350"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Revised%20RFC/near/195786350" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Revised.20RFC.html#195786350">(Apr 30 2020 at 00:17)</a>:</h4>
<p>I also don't think we should promise correct behavior when unwinding over destructors with longjmp on Windows.</p>



<a name="195849848"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Revised%20RFC/near/195849848" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Revised.20RFC.html#195849848">(Apr 30 2020 at 14:49)</a>:</h4>
<p>hmm, I don't know, I think I agree with <span class="user-mention" data-user-id="143274">@Amanieu</span> -- that seems similar to what I was saying about identifying scenarios --</p>



<a name="195849876"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Revised%20RFC/near/195849876" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Revised.20RFC.html#195849876">(Apr 30 2020 at 14:49)</a>:</h4>
<p>I think if I were coming to the RFC I would want to be able to "pattern match" the thing I am trying to do and get some idea of the rules around it</p>



<a name="195849988"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Revised%20RFC/near/195849988" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Revised.20RFC.html#195849988">(Apr 30 2020 at 14:50)</a>:</h4>
<p>I don't have a strong opinion about "forced unwind" vs other things, but there's definitely precedent for citing "longjmp" vs that category (I think that's what C++ does...?)</p>



<a name="195872133"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Revised%20RFC/near/195872133" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Revised.20RFC.html#195872133">(Apr 30 2020 at 17:16)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/210922-project-ffi-unwind/topic/Revised.20RFC/near/195849848" title="#narrow/stream/210922-project-ffi-unwind/topic/Revised.20RFC/near/195849848">said</a>:</p>
<blockquote>
<p>hmm, I don't know, I think I agree with <span class="user-mention silent" data-user-id="143274">Amanieu</span> -- that seems similar to what I was saying about identifying scenarios --</p>
</blockquote>
<p>that said</p>



<a name="195872151"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Revised%20RFC/near/195872151" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Revised.20RFC.html#195872151">(Apr 30 2020 at 17:16)</a>:</h4>
<p>I think that what this suggestion could also be 'encoded' into the detailed rule section</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>